<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="welcome" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    JVM_OOM分析 |  ChenyyのBlog
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">
  
<link rel="stylesheet" href="/css/custom.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

  

</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-Java/JVM_OOM"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  JVM_OOM分析
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2021/06/13/Java/JVM_OOM/" class="article-date">
  <time datetime="2021-06-13T13:21:21.000Z" itemprop="datePublished">2021-06-13</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Java/">Java</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.7k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">6 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <ul>
<li>Metaspace内存溢出</li>
<li>虚拟机栈内存溢出</li>
<li>堆内存溢出</li>
<li>堆外内存溢出</li>
<li>OOM排查命令</li>
</ul>
<span id="more"></span>



<h1 id="Metaspace内存溢出"><a href="#Metaspace内存溢出" class="headerlink" title="Metaspace内存溢出"></a>Metaspace内存溢出</h1><h2 id="原因"><a href="#原因" class="headerlink" title="原因"></a>原因</h2><ul>
<li><p>1.Metaspace内存大小直接用的默认或者设置的太小</p>
</li>
<li><p>2.cglib等技术动态生成类，控制不良，导致生成类过多，导致Metaspace塞满</p>
</li>
</ul>
<h2 id="定位"><a href="#定位" class="headerlink" title="定位"></a>定位</h2><ul>
<li>GC日志-&gt; MAT内存快照分析</li>
</ul>
<h1 id="虚拟机栈内存溢出"><a href="#虚拟机栈内存溢出" class="headerlink" title="虚拟机栈内存溢出"></a>虚拟机栈内存溢出</h1><h2 id="原因-1"><a href="#原因-1" class="headerlink" title="原因"></a>原因</h2><p>方法递归，线程内不停的调用/子调用方法，入栈-出栈，不停地消耗栈内存(一般设置1M)</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public static void sayHello(String name)&#123;</span><br><span class="line">sayHello(name);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="定位-1"><a href="#定位-1" class="headerlink" title="定位"></a>定位</h2><ul>
<li>系统日志打印异常信息，java.lang.StackOverflowError</li>
</ul>
<h1 id="堆内存溢出"><a href="#堆内存溢出" class="headerlink" title="堆内存溢出"></a>堆内存溢出</h1><h2 id="原因-2"><a href="#原因-2" class="headerlink" title="原因"></a>原因</h2><ul>
<li><p>1.系统承载高并发请求，导致短时间创建大量对象都是存活的，新对象放不下，触发OOM导致系统崩溃。</p>
</li>
<li><p>2.代码有内存泄漏的问题，创建很多对象没有及时取消他们的引用，导致GC无法回收。</p>
</li>
</ul>
<h2 id="定位-2"><a href="#定位-2" class="headerlink" title="定位"></a>定位</h2><ul>
<li><p>JVM设置OOM溢出时导出快照</p>
</li>
<li><p>日志文件错误信息捕捉</p>
</li>
<li><p>MAT分析快照</p>
<ul>
<li><p>先看占用内存最多的是什么对象</p>
</li>
<li><p>然后分析线程的调用栈</p>
</li>
<li><p>然后看是哪个方法却引起的。接着优化代码即可</p>
</li>
</ul>
</li>
</ul>
<h1 id="堆外内存溢出"><a href="#堆外内存溢出" class="headerlink" title="堆外内存溢出"></a>堆外内存溢出</h1><h2 id="原因-3"><a href="#原因-3" class="headerlink" title="原因"></a>原因</h2><ul>
<li><p>堆外内存申请使用，长时间未释放</p>
</li>
<li><p>进入了老年代，但是一直没触发Full GC导致堆外内存一直不能释放</p>
</li>
</ul>
<h2 id="定位-3"><a href="#定位-3" class="headerlink" title="定位"></a>定位</h2><ul>
<li><p>日志分析，java.lang.OutOfMemoryError: Direct buffer memory</p>
</li>
<li><p>MAT分析快照</p>
</li>
</ul>
<h1 id="奇葩问题"><a href="#奇葩问题" class="headerlink" title="奇葩问题"></a>奇葩问题</h1><h2 id="Tomcat参数设置导致OOM"><a href="#Tomcat参数设置导致OOM" class="headerlink" title="Tomcat参数设置导致OOM"></a>Tomcat参数设置导致OOM</h2><ul>
<li><p>max-http-header-size</p>
</li>
<li><p>请求头大小</p>
</li>
<li><p>设置了为10M，每个Tomcat线程运行时生成两个10M的byte数组，每个线程运行4s，直接导致OOM</p>
</li>
<li><p>Tomcat源码中定义了，每次调用会创建两个byte[]保存请求和响应</p>
</li>
</ul>
<h2 id="堆外内存溢出-1"><a href="#堆外内存溢出-1" class="headerlink" title="堆外内存溢出"></a>堆外内存溢出</h2><ul>
<li><p>Jetty通过NIO使用堆外内存，系统JVM参数设置新生代过小老年代很大，导致堆外内存引用进入老年底，长时间未触发Full GC导致一直无法释放，导致堆外内存OOM</p>
</li>
<li><p>NIO设计时考虑了GC问题，在NIO执行结束后会调用System.gc()方法，显示释放内存，不过我们一般的JVM参数设置会禁止System.gc()这种方法调用触发GC，导致无法释放触发OOM</p>
</li>
</ul>
<h2 id="自研RPC框架序列化问题导致OOM"><a href="#自研RPC框架序列化问题导致OOM" class="headerlink" title="自研RPC框架序列化问题导致OOM"></a>自研RPC框架序列化问题导致OOM</h2><ul>
<li><p>通信双方定义传输参数格式，然后接到参数后进行反序列化(转换成byte[])。进行后续逻辑处理</p>
</li>
<li><p>服务A修改参数格式未通知服务B，导致解析时一直失败。</p>
</li>
<li><p>RPC框架设计的一个机制是解析失败的话会把解析失败的这个byte[]放到内存中，等待后续分析</p>
</li>
<li><p>内存大小设置为了4GB，导致在服务B不感知参数格式变化的情况下，A不停调用，B不停解析失败放到内存中，直至占用打到4GB后直接触发OOM</p>
</li>
</ul>
<h1 id="查看日志是有效判断OOM种类的方法"><a href="#查看日志是有效判断OOM种类的方法" class="headerlink" title="查看日志是有效判断OOM种类的方法"></a>查看日志是有效判断OOM种类的方法</h1><ul>
<li><p>元数据溢出: java.lang.OutOfMemoryError: Metaspace</p>
</li>
<li><p>栈内存溢出: java.lang.StackOverflowError</p>
</li>
<li><p>堆内存溢出: java.lang.OutOfMemoryError: Java heap space</p>
</li>
<li><p>堆外内存溢出: java.lang.OutOfMemoryError: Direct buffer memory</p>
</li>
</ul>
<h1 id="OOM排查命令"><a href="#OOM排查命令" class="headerlink" title="OOM排查命令"></a>OOM排查命令</h1><h2 id="查看进程占用CPU使用情况"><a href="#查看进程占用CPU使用情况" class="headerlink" title="查看进程占用CPU使用情况"></a>查看进程占用CPU使用情况</h2><p>#jps 查看所有java进程，输出JVM中运行的进程状态信息</p>
<p>#top  查看cpu占用高进程</p>
<p>#top -p pid 查看某一进程下线程</p>
<p>#printf %x 线程ID 将异常的线程ID转换为十六进制值</p>
<p>#jstack 进程ID | grep 线程ID十六进制  输出进程的堆栈信息</p>
<p><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbWFnZXMyMDE1LmNuYmxvZ3MuY29tL2Jsb2cvNzM0NTU1LzIwMTYwNC83MzQ1NTUtMjAxNjA0MTkwOTU1MDA5NzYtMjcwMDc2OTcucG5n?x-oss-process=image/format,png" alt="img"></p>
<h2 id="查看进程占用内存使用情况"><a href="#查看进程占用内存使用情况" class="headerlink" title="查看进程占用内存使用情况"></a>查看进程占用内存使用情况</h2><p>#ps aux | sort -k4,4nr | head -n 10 查看内存占用前10名的程序</p>
<p>#ps -aux | grep xxx </p>
<p>第一个标注的地方是CPU和内存占用率，后面的943100是物理内存使用量，单位是k，此时kafka大约占用943M内存</p>
<p><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbWFnZXMyMDE1LmNuYmxvZ3MuY29tL2Jsb2cvNzM0NTU1LzIwMTYwNC83MzQ1NTUtMjAxNjA0MTkxMDA0MzU3NTctMjE5NTk2MDExLnBuZw?x-oss-process=image/format,png" alt="img"></p>
<h2 id="jstack查看java线程"><a href="#jstack查看java线程" class="headerlink" title="jstack查看java线程"></a>jstack查看java线程</h2><p>#jstack -l 线程ID 查看线程状态</p>
<p>#jstack -l 线程ID &gt; jstack.log  将线程信息存入文件中</p>
<p>值得关注的线程状态有：</p>
<ol>
<li>死锁，<em>*<em>*Deadlock*</em>*<em>（重点关注）*</em>*</em></li>
<li>执行中，Runnable</li>
<li>等待资源，<em>*<em>*</em>*Waiting on condition****（重点关注）****</em>*</li>
<li>等待获取监视器，<strong>Waiting on monitor entry（重点关注）</strong></li>
<li>暂停，Suspended</li>
<li>对象等待中，Object.wait() 或 TIMED_WAITING</li>
<li>阻塞，<em>*<em>*Blocked*</em>*<em>（重点关注）*</em>*</em></li>
<li>停止，Parked</li>
</ol>
<h2 id="jstat监控jvm内存"><a href="#jstat监控jvm内存" class="headerlink" title="jstat监控jvm内存"></a>jstat监控jvm内存</h2><p>#jstat -gc pid 5000 100</p>
<p>#jstat -gcutil pid 5000 100</p>
<p><strong>监控jvm各个区内存和GC的情况，每5秒打印一次，循环100次</strong></p>
<p><img src="https://img-blog.csdnimg.cn/20200514143354457.png" alt="img"></p>
<p><img src="https://img-blog.csdnimg.cn/20200514145305611.png" alt="img"></p>
<p>参数：</p>
<p>S0C：第一个幸存区的大小<br>S1C：第二个幸存区的大小<br>S0U：第一个幸存区的使用大小<br>S1U：第二个幸存区的使用大小<br>EC：伊甸园区的大小<br>EU：伊甸园区的使用大小<br>OC：老年代大小<br>OU：老年代使用大小<br>MC：方法区大小<br>MU：方法区使用大小<br>CCSC:压缩类空间大小<br>CCSU:压缩类空间使用大小<br>YGC：年轻代垃圾回收次数<br>YGCT：年轻代垃圾回收消耗时间<br>FGC：老年代垃圾回收次数<br>FGCT：老年代垃圾回收消耗时间<br>GCT：垃圾回收消耗总时间 </p>
<h2 id="jmap查看堆信息"><a href="#jmap查看堆信息" class="headerlink" title="jmap查看堆信息"></a>jmap查看堆信息</h2><p>#jmap -heap pid </p>
<p>打印一个堆的摘要信息，包括使用的GC算法、堆配置信息和各内存区域内存使用信息。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line">C:\Users\jjs&gt;jmap -heap 5932</span><br><span class="line">Attaching to process ID 5932, please wait...</span><br><span class="line">Debugger attached successfully.</span><br><span class="line">Server compiler detected.</span><br><span class="line">JVM version is 25.91-b15</span><br><span class="line"> </span><br><span class="line">using thread-local object allocation.</span><br><span class="line">Parallel GC with 4 thread(s)</span><br><span class="line"> </span><br><span class="line">#堆内存配置信息</span><br><span class="line">Heap Configuration:</span><br><span class="line">   MinHeapFreeRatio         = 0</span><br><span class="line">   MaxHeapFreeRatio         = 100</span><br><span class="line">   MaxHeapSize              = 1073741824 (1024.0MB)</span><br><span class="line">   NewSize                  = 42991616 (41.0MB)</span><br><span class="line">   MaxNewSize               = 357564416 (341.0MB)</span><br><span class="line">   OldSize                  = 87031808 (83.0MB)</span><br><span class="line">   NewRatio                 = 2</span><br><span class="line">   SurvivorRatio            = 8</span><br><span class="line">   MetaspaceSize            = 21807104 (20.796875MB)</span><br><span class="line">   CompressedClassSpaceSize = 1073741824 (1024.0MB)</span><br><span class="line">   MaxMetaspaceSize         = 17592186044415 MB</span><br><span class="line">   G1HeapRegionSize         = 0 (0.0MB)</span><br><span class="line"> </span><br><span class="line">#堆内存使用情况</span><br><span class="line">Heap Usage:</span><br><span class="line">#年轻代</span><br><span class="line">PS Young Generation</span><br><span class="line">Eden Space:</span><br><span class="line">   capacity = 60293120 (57.5MB)</span><br><span class="line">   used     = 44166744 (42.120689392089844MB)</span><br><span class="line">   free     = 16126376 (15.379310607910156MB)</span><br><span class="line">   73.25337285580842% used</span><br><span class="line">From Space:</span><br><span class="line">   capacity = 5242880 (5.0MB)</span><br><span class="line">   used     = 0 (0.0MB)</span><br><span class="line">   free     = 5242880 (5.0MB)</span><br><span class="line">   0.0% used</span><br><span class="line">To Space:</span><br><span class="line">   capacity = 14680064 (14.0MB)</span><br><span class="line">   used     = 0 (0.0MB)</span><br><span class="line">   free     = 14680064 (14.0MB)</span><br><span class="line">   0.0% used</span><br><span class="line">#年老代</span><br><span class="line">PS Old Generation</span><br><span class="line">   capacity = 120061952 (114.5MB)</span><br><span class="line">   used     = 19805592 (18.888084411621094MB)</span><br><span class="line">   free     = 100256360 (95.6119155883789MB)</span><br><span class="line">   16.496143590935453% used</span><br><span class="line"> </span><br><span class="line">20342 interned Strings occupying 1863208 bytes.</span><br></pre></td></tr></table></figure>

<p><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbWcyMDIwLmNuYmxvZ3MuY29tL2ktYmV0YS8xNTA4MzMzLzIwMjAwMy8xNTA4MzMzLTIwMjAwMzAzMTY1NDUzMzk0LTE2Njk3OTg2OS5wbmc?x-oss-process=image/format,png" alt="img"></p>
<h2 id="jmap查看内存占用情况"><a href="#jmap查看内存占用情况" class="headerlink" title="jmap查看内存占用情况"></a>jmap查看内存占用情况</h2><p>#jmap -histo:live pid | head -n 20</p>
<p>pid是进程号，20表示排名前二十，instances表示实例数量，bytes表示占用内存大小（1M=1024KB,1KB=1024Bytes）</p>
<ul>
<li><strong>注意事项：jmap -dump:live 以及 jmap -histo:live都会触发Full GC</strong></li>
</ul>
<p><img src="https://gitee.com/chenyy-2017/pic/raw/master/note/image-20210613164019242.png"></p>
<p><img src="upload%5Cimage-20210613164019242.png" alt="image-20210613164019242"></p>
<p>#jmap -dump:format=b,file=dumpFileName <pid></p>
<p>生成堆转储快照dump文件。可以用 memory analyse 查看<br>　　<img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbWcyMDIwLmNuYmxvZ3MuY29tL2ktYmV0YS8xNTA4MzMzLzIwMjAwMy8xNTA4MzMzLTIwMjAwMzAzMTcxMzAzMTA5LTc2ODcwNzcwNC5wbmc?x-oss-process=image/format,png" alt="img"></p>
<p><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbWcyMDIwLmNuYmxvZ3MuY29tL2ktYmV0YS8xNTA4MzMzLzIwMjAwMy8xNTA4MzMzLTIwMjAwMzAzMTcxMzM2MzE4LTU2NzAyODcyMC5wbmc?x-oss-process=image/format,png" alt="img"></p>
<h2 id="对dump文件进行分析"><a href="#对dump文件进行分析" class="headerlink" title="对dump文件进行分析"></a>对dump文件进行分析</h2><p><strong>通过MAT工具（eclipse）、JProfiler（idea）、jhat（JDK自带）进行分析</strong></p>
<p>#jhat -port pid <file>  通过jhat对dump文件进行分析</p>
<p>jhat -port 29729 ../tmp/dump.dat，打开浏览器进行访问：<a target="_blank" rel="noopener" href="http://localhost:29729/">http://localhost:29729/</a></p>
<p><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbWcyMDIwLmNuYmxvZ3MuY29tL2ktYmV0YS8xNTA4MzMzLzIwMjAwMy8xNTA4MzMzLTIwMjAwMzAzMTcxODQxMDc1LTEzMzc1NjY0MzgucG5n?x-oss-process=image/format,png" alt="img"></p>
<p><img src="https://img-blog.csdnimg.cn/20200115201520547.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly96aGFuZ3h1ZWxpYW5nLmJsb2cuY3Nkbi5uZXQ=,size_16,color_FFFFFF,t_70" alt="img"></p>
<p>参考：</p>
<p>Linux命令-查看内存、GC情况及jmap 用法：<a target="_blank" rel="noopener" href="https://chenchenchen.blog.csdn.net/article/details/106048793">https://chenchenchen.blog.csdn.net/article/details/106048793</a></p>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2021/06/13/Java/JVM_OOM/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java/" rel="tag">Java</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2021/06/14/component/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            redis数据结构
          
        </div>
      </a>
    
    
      <a href="/2021/06/13/Java/%E7%BA%BF%E7%A8%8B/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">线程</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2021
        <i class="ri-heart-fill heart_icon"></i> Chenyy
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="ChenyyのBlog"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">文章</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/book">收藏</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about/me">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>